<template>
  <div>
    <el-container>
      <el-header class="homeHeader">
        <div class="title">云E办</div>
        <div>
          <el-button
            icon="el-icon-chat-round"
            type="text"
            size="normal"
            circle
            style="color: #fff"
            @click="goChat"
          ></el-button>
          <el-dropdown class="userInfo" @command="commandHandler">
            <span class="el-dropdown-link">
              <h6>{{ user.name }}</h6>
              <i>
                <img :src="user.userFace" />
              </i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="userinfo">个人中心</el-dropdown-item>
              <el-dropdown-item command="setting">设置</el-dropdown-item>
              <el-dropdown-item command="logout">注销</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <el-menu router unique-opened>
            <el-submenu
              :index="index + ''"
              v-for="(item, index) in routes"
              :key="index"
              v-show="!item.hidden"
            >
              <template slot="title"
                ><i
                  :class="item.iconCls"
                  style="color: rgb(24, 49, 83); margin-right: 5px"
                ></i
                >{{ item.name }}</template
              >
              <el-menu-item
                :index="children.path"
                v-for="(children, index) in item.children"
                :key="index"
                >{{ children.name }}</el-menu-item
              >
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main style="height: 100%">
          <el-breadcrumb v-if="this.$router.currentRoute.path != '/home'">
            <el-breadcrumb-item :to="{ path: '/home' }"
              >首页</el-breadcrumb-item
            >
            <el-breadcrumb-item>{{
              this.$router.currentRoute.name
            }}</el-breadcrumb-item>
          </el-breadcrumb>
          <div
            v-if="this.$router.currentRoute.path == '/home'"
            class="homeWelcome"
          >
            <svg viewBox="0 0 400 200">
              <text x="0" y="70%">HELLO!</text>
            </svg>
          </div>
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: "Home",
  data() {
    return {
      // user: JSON.parse(window.sessionStorage.getItem("user")),
    };
  },
  methods: {

    goChat() {
      this.$router.push('/chat')
    },
    commandHandler(command) {
      if (command == "logout") {
        this.$confirm("确定是否注销", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            //注销登录
            this.postRequest("/logout");
            //  清空用户信息
            window.sessionStorage.removeItem("tokenStr");
            window.sessionStorage.removeItem("user");
            //清空菜单信息
            this.$store.commit("initRoutes", []);
            //转到登录页
            this.$router.replace("/");
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消",
            });
          });
      }
      if(command == 'userinfo') {
        this.$router.push('/userinfo')
      }
    },
  },
  computed: {
    routes() {
      return this.$store.state.routes;
    },
    user() {
      return this.$store.state.currentAdmin
    }
  },
  mounted() {},
};
</script>

<style scoped>
@import url("https://fonts.googleapis.com/css2?family=Bangers&family=Homemade+Apple&family=Sacramento&display=swap");
.homeHeader {
  background: rgb(24, 49, 83);
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
}
.homeHeader .title {
  height: 100%;
  color: #fff;
  font-size: 30px;
  line-height: 60px;
}
.homeHeader .userInfo {
  cursor: pointer;
}
.el-dropdown-link {
  width: 110px;
  display: flex;
  justify-content: flex-end;
  height: 100%;
  color: #fff;
}
.el-dropdown-link i {
  display: inline-block;
}
.el-dropdown-link img {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  margin-top: 6px;
  margin-left: 10px;
}

.homeWelcome {
  width: 100%;
  height: 100%;
  display: flex;
  font-family: "Bangers", cursive;
  background: #fff;
}

.homeWelcome svg {
  width: 600px;
  height: 300px;
  margin: auto;
}

.homeWelcome svg text {
  text-transform: uppercase;
  animation: stroke 5s;
  letter-spacing: 10px;
  font-size: 150px;
}

@keyframes stroke {
  0% {
    fill: rgba(72, 138, 20, 0);
    stroke: rgba(54, 95, 160, 1);
    stroke-dashoffset: 25%;
    stroke-dasharray: 0 50%;
    stroke-width: 0.8;
  }

  50% {
    fill: rgba(72, 138, 20, 0);
    stroke: rgba(54, 95, 160, 1);
    stroke-width: 1.2;
  }

  70% {
    fill: rgba(72, 138, 20, 0);
    stroke: rgba(54, 95, 160, 1);
    stroke-width: 1.5;
  }

  90%,
  100% {
    fill: rgba(72, 138, 204, 1);
    stroke: rgba(54, 95, 160, 0);
    stroke-dashoffset: -25%;
    stroke-dasharray: 50% 0;
    stroke-width: 0;
  }
}
</style>